
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_CurrencyDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            Currency currency = CurrencyManager.GetByCurrencyID(this.CurrencyID);
            if (currency != null)
            {
                this.txtName.Text = currency.Name;
                this.txtCurrencyCode.Text = currency.CurrencyCode;
                this.txtDisplayLocale.Text = currency.DisplayLocale;
                this.txtRate.Value = currency.Rate;
                this.cbPublished.Checked = currency.Published;
                this.txtDisplayOrder.Value = currency.DisplayOrder;
                this.lblCreatedOn.Text = currency.CreatedOn.ToString();
                this.lblUpdatedOn.Text = currency.UpdatedOn.ToString();
            }
            else
                Response.Redirect("Currencies.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    Currency currency = CurrencyManager.GetByCurrencyID(this.CurrencyID);
                    if (currency != null)
                    {
                        currency = CurrencyManager.UpdateCurrency(currency.CurrencyID, txtName.Text, txtCurrencyCode.Text,
                        txtRate.Value, txtDisplayLocale.Text, cbPublished.Checked, txtDisplayOrder.Value,
                        currency.CreatedOn, DateTime.Now);
                        Response.Redirect("CurrencyDetails.aspx?CurrencyID=" + currency.CurrencyID.ToString());
                    }
                    else
                        Response.Redirect("Currencies.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                CurrencyManager.DeleteCurrency(this.CurrencyID);
                Response.Redirect("Currencies.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int CurrencyID
        {
            get
            {
                return CommonHelper.QueryStringInt("CurrencyID");
            }
        }
    }
}
